package com.kcht.sylyg08.service;

import com.kcht.adp.common.log.Logger;
import com.kcht.adp.pagination.Page;
import com.kcht.sylyg08.dao.IContainerTagBoundDao;
import com.kcth.sylyg08.entity.ContainerTagBound;

import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
import java.util.List;
import java.util.Objects;

@RequestScoped
@Transactional()
public class ContainerTagBoundService {
    @Inject
    private Logger logger;
    @EJB
    private IContainerTagBoundDao dao;

    public void save(ContainerTagBound bound) {
        if (bound.getId() == null) {
            dao.save(bound);
        } else {
            dao.merge(bound);
        }
    }

    public Page<ContainerTagBound, ContainerTagBound> list(Page<ContainerTagBound, ContainerTagBound> page) {
        return dao.getPageListByJPQL("Bound.queryBoundList",page);
    }

    public void delete(List<Integer> ids) {
        ids.forEach(id->{
            ContainerTagBound bound = dao.get(id.longValue());
            if(Objects.nonNull(bound)){
                dao.delete(id.longValue());
            }
        });
    }
}
